package com.hibernate;

import com.google.gson.Gson;
import com.hibernate.dao.UserDao;
import com.hibernate.entities.tb_users;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by francis on 2016/12/4.
 */
public class Startup {
    public static void main(String[] args) {
        count();

//        getAll();

        System.out.println("ok");

    }

    private static void count(){
//        System.out.println(new UserDao().count1());
//        System.out.println(new UserDao().count2());
        System.out.println(new UserDao().count3());
    }

    //查询所有的数据
    private static void getAll() {
        List<tb_users> tmpUsers = new UserDao().getAll(tb_users.class);
        System.out.println(new Gson().toJson(tmpUsers));
    }

    private static void addList() {
        List<tb_users> tmpUsers = new ArrayList<tb_users>();

        for (int i = 0; i <= 100; i++) {
            tmpUsers.add(new tb_users(
                    new Date().getTime()+i,
                    "francis" + String.valueOf(i + 1),
                    "123456",
                    ""));
        }

        System.out.println(new UserDao().addList(tmpUsers, tb_users.class));
    }

    private static String md5(String str) {
        try {
            // 生成一个MD5加密计算摘要
            MessageDigest md = MessageDigest.getInstance("MD5");
            // 计算md5函数
            md.update(str.getBytes());
            // digest()最后确定返回md5 hash值，返回值为8为字符串。因为md5 hash值是16位的hex值，实际上就是8位的字符
            // BigInteger函数则将8位的字符串转换成16位hex值，用字符串来表示；得到字符串形式的hash值
            return new BigInteger(1, md.digest()).toString(16);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
